package cn.enited.devtools.apiaggregator.validator;

import cn.enited.devtools.apiaggregator.anno.IsMail;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class ValidateMail implements ConstraintValidator<IsMail, String> {

    @Override
    public void initialize(IsMail constraintAnnotation) {

    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if (StrUtil.isBlank(s)) {
            return true;
        }
        return Validator.isEmail(s);
    }
}
